<template>
    <a-button-group shape="square">
        <a-button type="primary" icon="ios-arrow-back" ghost @click="utils.doUrl(backurl)"
            v-if="!utils.isEmpty(backurl)">返回</a-button>
        <template v-for="(btn, index) in buttons" :key="index">
            <a-button type="primary" @click="doAction(btn)" v-has="btn.authorize" v-if="btn.isShow == 1">
                <icon-font :type="`icon-${btn.icon}`" v-if="btn.icon"></icon-font>
                <span style="margin-left: 5px;">{{ btn.name }}</span>
            </a-button>
        </template>

    </a-button-group>
</template>

<script lang="ts">
import { ref, toRefs } from '@vue/reactivity';
import router from '@/router/router';
import utils from '@/utils/utils';

export default {
    props: { backurl: String },
    setup(props: any, { emit }) {
        const { backurl } = toRefs(props)
        const buttons = ref([] as any);
        const route = router.currentRoute;
        buttons.value = route.value.meta.buttons as any;

        const doAction = (btn: any) => {
            let actions = btn.authorize && btn.authorize != "" ? btn.authorize.split(":") : null;
            const action = actions && actions != null ? actions[actions.length - 1] : null;
            if (action) {
                console.log('执行：' + action + "回调")
                emit(action);
            } else {
                console.log("事件没有找到回调方法！");
                console.log(btn)
            }
        }
        return { doAction, buttons, backurl, utils }
    }
}

</script>

<style scoped>

</style>
